package com.aaa.inside.service.impl;

import com.aaa.entity.inside.Move;
import com.aaa.inside.mapper.MoveMapper;
import com.aaa.inside.service.MoveService;
import com.aaa.vo.R;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author aaa
 * @since 2020-11-27
 */
@Service
public class MoveServiceImpl extends ServiceImpl<MoveMapper, Move> implements MoveService {

    @Override
    public List<Map> selectComByWareId(Long warehouseid) {
        return this.baseMapper.selectComByWareId(warehouseid);
    }

    @Override
    public List<Map> selectOriLocByCombar(String commoditybar, Long warehouseid) {
        return this.baseMapper.selectOriLocByCombar(commoditybar,warehouseid);
    }

    @Override
    public List<Map> selectTarLocByOrLoc(String oldlocatorcode,Long warehouseid) {
        return this.baseMapper.selectTarLocByOrLoc(oldlocatorcode,warehouseid);
    }

    @Override
    public R searchMove(Integer page, Integer limit, Move move) {
        Page<Move> pageinfo=new Page<>(page,limit);
        String commoditybar=move.getCommoditybar();
        String commodityname=move.getCommodityname();
        String locatorcode=move.getLocatorcode();
        String locatorname=move.getLocatorname();
        String state=move.getState();
        QueryWrapper<Move> queryWrapper=new QueryWrapper<>();
        if(StringUtils.isNotEmpty(commoditybar)){
            queryWrapper.like("commoditybar",commoditybar);
        }
        if(StringUtils.isNotEmpty(commodityname)){
            queryWrapper.like("commodityname",commodityname);
        }
        if(StringUtils.isNotEmpty(locatorcode)){
            queryWrapper.like("locatorcode",locatorcode);
        }
        if(StringUtils.isNotEmpty(locatorname)){
            queryWrapper.like("locatorname",locatorname);
        }
        if(StringUtils.isNotEmpty(state)){
            queryWrapper.like("state",state);
        }
        this.baseMapper.selectPage(pageinfo,queryWrapper);
        return R.ok().message("查询成功").data("pageinfo",pageinfo);
    }
}
